require 'logger'
class Users::SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create]
  #force_ssl   #强制要求类控制器使用SSL访问

  def initialize
    super
    @log=Logger.new(STDOUT)
  end

  # GET /resource/sign_in
  def new
     super

    @log.info("new方法被调用")



  end

  # POST /resource/sign_in
  def create
    user_obj = User.new
    #获取客户端表单中提交的值
    enc_pass=params[:user][:encrypted_password]
    email = params[:user][:email]

    user = user_obj.find_user_email(email)
    if user then
      session[:email] = user.email
      @log.info "恭喜，用户名 #{email} 登陆成功 "
    else
      @log.info "对不起，用户名#{email}不存在 "
    end

    @log.info('客户端要求登录用户名：'+email.to_s)
    @log.info("当前用户：%s" % (current_user))

    @log.info("会话状态：%s" % user_signed_in?)

    redirect_to posts_path
  end

  # DELETE /resource/sign_out
   def destroy
     super
   end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_sign_in_params
  #   devise_parameter_sanitizer.for(:sign_in) << :attribute
  # end
end
